package controller

import (
	"github.com/gofiber/fiber/v2"
	"guns-excel/internal/app/service"
	"guns-excel/internal/pkg/util/result"
)

// 获取mysql数据库中存在的表名
func GetModels(ctx *fiber.Ctx) error {
	dataBaseName := ctx.Query("dataBaseName")
	models, err := service.GetModels(ctx, dataBaseName)
	if err != nil {
		return err
	}
	return ctx.JSON(result.OK.WithData(models))
}

// 根据表名获取字段
func GetFieldByTableName(ctx *fiber.Ctx) error {
	dataBaseName := ctx.Query("dataBaseName")
	tableName := ctx.Query("tableName")
	fieldByTableName, err := service.GetFieldByTableName(ctx, dataBaseName, tableName)
	if err != nil {
		return err
	}
	return ctx.JSON(result.OK.WithData(fieldByTableName))
}
